﻿using Ec_System.Models.Web;
using Ilongshi.Oversea.DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Ec_System.Service.Web
{
    public class CustomerComplaintService
    {
        /// <summary>
        /// 添加投诉
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AddComplaint(CustomerComplaintData model)
        {
            var cmd = DataCommandManager.GetDataCommand("AddComplaint");
            cmd.SetParameterValue("@CustomerLoginId", model.CustomerLoginId);
            cmd.SetParameterValue("@ComplaintType", model.ComplaintType);
            cmd.SetParameterValue("@Title", model.Title);
            cmd.SetParameterValue("@OrderId", model.OrderId);
            cmd.SetParameterValue("@Contents", model.Contents);

            return cmd.ExecuteNonQuery();
        }

        /// <summary>
        /// 获取用户投诉列表 (带分页)
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public CustomerComplaintResponseData GetComplaintListWithPage(CustomerComplaintRequestData request)
        {
            var cmd = DataCommandManager.GetDataCommand("GetComplaintListWithPage");
            cmd.SetParameterValue("@PageIndex", request.PageIndex);
            cmd.SetParameterValue("@PageSize", request.PageSize);
            cmd.SetParameterValue("@LoginID", request.LoginID);

            var result = new CustomerComplaintResponseData()
            {
                PageIndex = request.PageIndex,
                PageSize = request.PageSize,
                Result = cmd.ExecuteEntityList<CustomerComplaintData>(),
                TotalCount = cmd.GetParameterValue<int>("@TotalCount")
            };

            return result;
        }

        /// <summary>
        /// 根基ComplaintID获取一条记录
        /// </summary>
        /// <param name="complaintID"></param>
        /// <returns></returns>
        public CustomerComplaintData GetComplaintByID(string complaintID)
        {
            var cmd = DataCommandManager.GetDataCommand("GetComplaintByID");
            cmd.SetParameterValue("@ComplaintID", complaintID);

            return cmd.ExecuteEntity<CustomerComplaintData>();
        }

        /// <summary>
        /// 根据 ComplaintID 获取明细
        /// </summary>
        /// <param name="complaintID"></param>
        /// <returns></returns>
        public List<ComplaintDetailData> GetComplaintDetailByComplaintID (string complaintID)
        {
            var cmd = DataCommandManager.GetDataCommand("GetComplaintDetailByComplaintID");
            cmd.SetParameterValue("@ComplaintID", complaintID);

            return cmd.ExecuteEntityList<ComplaintDetailData>();
        }

        /// <summary>
        /// 添加一条投诉明细记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AddComplaintDetail(ComplaintDetailData model)
        {
            var cmd = DataCommandManager.GetDataCommand("AddComplaintDetail");
            cmd.SetParameterValue("@ComplaintID", model.ComplaintID);
            cmd.SetParameterValue("@Contents", model.Contents);

            return cmd.ExecuteNonQuery();
        }

    }
}
